<template>
	<div :class="{homenewzone:(newzoneclass=='true')}">
		<img class="newzonebg" :src="newZonedata.publicityPicture||'static/image/demo1.png'" @click='jumpEvent()' />
	</div>
</template>

<script>
	import { NAVIGATE } from "../../config/postMessage-types";
	export default {
		props: {
			newZonedata: {
				type: Object,
				default: () => {}
			},
			screenHeight: {
				type: String,
				default: '3.5'
			},
			newzoneclass: {
				type: String,
				default: 'true'
			},
		},
		data() {
			return {

			}
		},
		components: {

		},
		methods: {
			/**
			 * isApp: 代表页面是否在RNAPP中打开的
			 */
			jumpEvent() {
				if (!this.newZonedata.extendField) return;
				if (!this.isApp) {
					var urldata = JSON.parse(this.newZonedata.extendField).url.path
					if(urldata) {
						this.$router.push({
							name: "MiddleWare",
							params: {
								pageName: urldata
							}
						})
					}
				} else if(this.isApp) {
					var urldata = JSON.parse(this.newZonedata.extendField).url
					if (urldata.valueArray[0] == '商品详情页面' ) {
						this.gotornpage('Detail', urldata.path.split("=")[1])
					} else if (urldata.valueArray[0] == '分类页面'){
						this.gotornpage('GoodsClassify', urldata.path.split("=")[1])
					} else if (urldata.valueArray[0] == '其他页面') {
						if(urldata.path == 'IntegralBuy') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}else{
								this.gotornpage(urldata.path)
							}
						}else if(urldata.path == 'Coupons'){
							this.gotornpage('CouponsAcquire')
						} else if (urldata.path == 'buyGiftCard') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							} else{
								this.gotornpage('BuyGiftCard')
							}
						} else if(urldata.path == 'foodChecked'){
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}
							else{
								this.gotornpage('FoodCheck')
							}
						} else if(urldata.path == 'prize_card'){
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'integral'){
							console.log("urldata.path",urldata.path)
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'login'){
							this.gotornpage('Login')
						} else if(urldata.path == 'register'){
							this.gotornpage('Regrester')
						} else {
							this.$router.push({
								name: "MiddleWare",
								params: {
									pageName: urldata.path
								}
							})
						}
					}
				}
			},
			gotornpage(page, code) {
				let params = {}
				if(page=='Detail'){
					params = {
						screen: page,
						params:{
							goodsCode: code
						}
					}
				}else if(page=='GoodsClassify'){
					params = {
						screen: page,
						params:{
							classCode: code
						}
					}
				}else{
					params = {
						screen: page,
					}
				}
				let goBackIns = {
					type: NAVIGATE,
					params: params
				}
				window.postMessage(JSON.stringify(goBackIns));
			}
		},
		computed: {
			isApp() {
				return window.isApp;
			}
		},
		mounted() {

		},
	}
</script>

<style>
	.homenewzone {
		background-color: #fff;
		/*padding: 0.75rem 0rem;*/
		/* padding: 0.75rem; */
	}
	
	.newzonebg {
		margin: 0 auto;
		width: 100%;
		/*height: 3.5rem;*/
		/*border-radius: 4rem;*/
	}
</style>